Skip to content

Remove dead pre-Chef-15 branches from the monkey patches#41

Open
tas50 wants to merge 1 commit into
chef:mainfrom
tas50:cleanup/remove-dead-chef-version-branches
Open

Remove dead pre-Chef-15 branches from the monkey patches#41
tas50 wants to merge 1 commit into
chef:mainfrom
tas50:cleanup/remove-dead-chef-version-branches

Conversation

@tas50

@tas50 tas50 commented Jun 28, 2026

Copy link
Copy Markdown

Summary

The gemspec requires chef >= 17, which makes several version-conditional branches inside the extension monkey patches permanently unreachable. This removes that dead code, simplifying the most version-fragile part of ChefSpec.

What was dead, and why

  • extensions/chef/lwrp_base.rb branched on defined?(Chef::Provider::InlineResources). InlineResources was removed in Chef 13.0 (the code's own else # >= 13.0 comment notes this), so at Chef ≥ 17 only the compile_and_converge_action branch can run.
  • extensions/chef/provider.rb and extensions/chef/shell_out.rb (both ResourceShellOut and MixinShellOut) branched on HAS_SHELLOUT_COMPACTED = Gem::Requirement.create("> 14.2"). At Chef ≥ 17 that's always satisfied, so the legacy shell_out fallbacks are dead and only the shell_out_compacted hooks remain.
  • api/stubs_for.rb selected the hook method with the same always-true check, and defined the now-unused HAS_SHELLOUT_COMPACTED constant.

Changes

  • Dropped the unreachable branches in all four files.
  • Removed the unused HAS_SHELLOUT_COMPACTED constant.
  • No behavior change on supported Chef versions.

Testing

  • bundle exec rspec spec/unit/162 examples, 0 failures.
  • Acceptance examples that exercise the patched paths:
    • stubs_for + execute (drive shell_out_compacted) → 41 examples, 0 failures.
    • custom_resource, custom_resource_block, heavy_provider_light_resource (drive compile_and_converge_action) → 7 examples, 0 failures.
  • cookstyle --chefstyle -c .rubocop.yml on the changed files → no offenses.

The gemspec requires chef >= 17, which makes several version-conditional
branches in the extension monkey patches unreachable:

- lwrp_base.rb guarded on `defined?(Chef::Provider::InlineResources)`,
  which Chef removed in 13.0; only the >= 13 branch can run now.
- provider.rb and shell_out.rb (both modules) branched on
  HAS_SHELLOUT_COMPACTED ("> 14.2"); at chef >= 17 the legacy `shell_out`
  fallbacks are dead, so only the `shell_out_compacted` hooks remain.
- stubs_for.rb chose the hook method via the same always-true check.

Drop the dead branches and the now-unused HAS_SHELLOUT_COMPACTED
constant. Behavior is unchanged on supported Chef versions.

Signed-off-by: Tim Smith <tsmith84@proton.me>
@tas50
tas50 requested review from a team and jaymzh as code owners June 28, 2026 05:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant